/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MainPackage.Views;

import MainPackage.Nahrungsmittel;
import MainPackage.NahrungsmittelList;
import javax.swing.JOptionPane;

/**
 *
 * @author n.kaminski d.chauvistre
 */
public class NahrungsmittelErstellen extends javax.swing.JDialog {

    private NahrungsmittelList nahrung = null;
    private static boolean neu;
    /**
     * Creates new form NahrungsmittelErstellen
     */
    public NahrungsmittelErstellen(java.awt.Frame parent, boolean modal, NahrungsmittelList nahrung) {
        super(parent, modal);
        this.nahrung=nahrung;
        initComponents();
    }
    
    /**
     * Erstellt Fenster zur neuen Eingabe eines Nahrungsmittels
     * @param parent
     * @param nahrung 
     */
    public static void showToNew(java.awt.Frame parent, NahrungsmittelList nahrung){
        neu=true;
        NahrungsmittelErstellen nme = new NahrungsmittelErstellen(parent, true, nahrung);
        nme.setVisible(true);
        
        
    }

    static int id; // Index des aktuellen bearbeiteten Nahrungsmittel falls nicht neu
    /**
     * Erstellt Fenster zur Bearbeitung eines Nahrungsmittels.
     * Lädt werte des aktuellen Nahrungsmittels aus
     * @param parent
     * @param nahrung 
     * @param index 
     */
    public static void showToOld(java.awt.Frame parent, NahrungsmittelList nahrung,int index){
        neu=false;
        id=index;
        NahrungsmittelErstellen nme = new NahrungsmittelErstellen(parent, true, nahrung);
        
        Nahrungsmittel bN= nahrung.getNahrungsmittelbyIndex(index);
        nme.nahrung=nahrung;
        nme.name.setText(bN.getName());
        nme.kiloCal.setText(String.valueOf(bN.getKcal()));
        nme.broteinheiten.setText(String.valueOf(bN.getBroteinheiten()));
        nme.kohlenhydrate.setText(String.valueOf(bN.getKohlenhydrate()));
        nme.eiweiss.setText(String.valueOf(bN.getEiweiss_g()));
        nme.cholesterin.setText(String.valueOf(bN.getCholesterin_mg()));
        nme.fett.setText(String.valueOf(bN.getFett_g()));
        nme.ungesFett.setText(String.valueOf(bN.getUngesFS_g()));
        
        nme.natrium.setText(String.valueOf(bN.getNatrium_mg()));
        nme.kalium.setText(String.valueOf(bN.getNatrium_mg()));
        nme.magnesium.setText(String.valueOf(bN.getMagnesium_mg()));
        nme.calcium.setText(String.valueOf(bN.getCalcium_mg()));
        nme.phosphor.setText(String.valueOf(bN.getPhosphor_mg()));
        nme.eisen.setText(String.valueOf(bN.getEisen_mg()));
        nme.zink.setText(String.valueOf(bN.getZink_mg()));
        
        nme.vitaminA.setText(String.valueOf(bN.getVitamin_A_mueg()));
        nme.vitaminB1.setText(String.valueOf(bN.getVitamin_B1_mg()));
        nme.vitaminB2.setText(String.valueOf(bN.getVitamin_B2_mg()));
        nme.vitaminB6.setText(String.valueOf(bN.getVitamin_B6_mg()));
        nme.vitaminC.setText(String.valueOf(bN.getVitamin_C_mg()));
        nme.vitaminE.setText(String.valueOf(bN.getVitamin_E_mg()));
        nme.folsaeure.setText(String.valueOf(bN.getFolsaeure_mueg()));
        nme.carotin.setText(String.valueOf(bN.getCarotin_mg()));
        
        
        
        
        nme.setVisible(true);
        
        
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        kiloCal = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        broteinheiten = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        kohlenhydrate = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        eiweiss = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cholesterin = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        fett = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        ungesFett = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        natrium = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        kalium = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        magnesium = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        calcium = new javax.swing.JTextField();
        phosphor = new javax.swing.JTextField();
        eisen = new javax.swing.JTextField();
        zink = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        vitaminA = new javax.swing.JTextField();
        vitaminB1 = new javax.swing.JTextField();
        vitaminB2 = new javax.swing.JTextField();
        vitaminB6 = new javax.swing.JTextField();
        vitaminC = new javax.swing.JTextField();
        vitaminE = new javax.swing.JTextField();
        folsaeure = new javax.swing.JTextField();
        carotin = new javax.swing.JTextField();
        SaveButton = new javax.swing.JButton();
        AbbrechenButton = new javax.swing.JButton();
        jLabel27 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(new java.awt.Color(240, 240, 240));
        setIconImage(null);
        setResizable(false);

        jLabel1.setText("Name");

        jLabel2.setBackground(new java.awt.Color(180, 180, 180));
        jLabel2.setText("Energieträger");
        jLabel2.setOpaque(true);

        jLabel3.setText("Kilo Kalorien (kcal)");

        jLabel4.setText("Broteinheiten");

        jLabel5.setText("Kohlenhydrate");

        jLabel6.setText("Eiweiß (g)");

        jLabel7.setText("Cholesterin (mg)");

        jLabel8.setText("Fett (g)");

        jLabel9.setText("unges. FS (g)");

        jLabel10.setBackground(new java.awt.Color(180, 180, 180));
        jLabel10.setText("Mineralstoffe");
        jLabel10.setOpaque(true);

        jLabel11.setText("Natrium (mg)");

        jLabel12.setText("Kalium (mg)");

        jLabel13.setText("Magnesium (mg)");

        jLabel14.setText("Calcium (mg)");

        jLabel15.setText("Phosphor (mg)");

        jLabel16.setText("Eisen (mg)");

        jLabel17.setText("Zink (mg)");

        jLabel18.setBackground(new java.awt.Color(180, 180, 180));
        jLabel18.setText("Vitamine");
        jLabel18.setOpaque(true);

        jLabel19.setText("Vitamin A (µg)");

        jLabel20.setText("Vitamin B1 (mg)");

        jLabel21.setText("Vitamin B2 (mg)");

        jLabel22.setText("Vitamin B6 (mg)");

        jLabel23.setText("Vitamin C (mg)");

        jLabel24.setText("Vitamin E (mg)");

        jLabel25.setText("Folsäure (µg)");

        jLabel26.setText("Carotin (mg)");

        SaveButton.setBackground(getBackground());
        SaveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GFX/Save.png"))); // NOI18N
        SaveButton.setText("Speichern");
        SaveButton.setBorderPainted(false);
        SaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveButtonActionPerformed(evt);
            }
        });

        AbbrechenButton.setBackground(getBackground());
        AbbrechenButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GFX/Loeschen.png"))); // NOI18N
        AbbrechenButton.setText("Abbrechen");
        AbbrechenButton.setBorderPainted(false);
        AbbrechenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AbbrechenButtonActionPerformed(evt);
            }
        });

        jLabel27.setBackground(new java.awt.Color(180, 180, 180));
        jLabel27.setText("Angaben für 100g");
        jLabel27.setOpaque(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cholesterin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(eiweiss, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(kohlenhydrate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(kiloCal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(broteinheiten, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(fett, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(ungesFett, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(magnesium, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(kalium, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(natrium, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(zink, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(calcium, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(phosphor, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(eisen, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(SaveButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(AbbrechenButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(113, 113, 113)
                                .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel20)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(vitaminB1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel19)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(vitaminA, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel26)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(carotin, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel21)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(vitaminB2, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel22)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(vitaminB6, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(vitaminC, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel24)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(vitaminE, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel25)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(folsaeure, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jLabel27, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel27)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(kiloCal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(broteinheiten, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(kohlenhydrate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(eiweiss, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cholesterin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(fett, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(ungesFett, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(natrium, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(kalium, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(magnesium, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(calcium, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(phosphor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(eisen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(zink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(vitaminA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(vitaminB1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(vitaminB2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(vitaminB6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(vitaminC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(vitaminE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(folsaeure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(carotin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SaveButton)
                    .addComponent(AbbrechenButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Speichert Eingabe in Nahrungsmittelliste
     * @param evt 
     */
    private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
       double kcal, kohy, brotE, eiw, chol, fet, unFett,
                natr, kali, magn, calc, phosp, eise, zi,
                vitA, vitB1, vitB2, vitB6, vitC, vitE, fols, carot;
        
        /**
         * initialisieren mit 0 
         */
        kcal=kohy=brotE=eiw=chol=fet=unFett=
        natr=kali=magn=calc=phosp=eise=zi=
        vitA=vitB1=vitB2=vitB6=vitC=vitE=fols=carot = 0;
        
        /**
         * Werte prüfen -> wirft Fehlermeldung
         */
       try{          
           kcal=Double.parseDouble(kiloCal.getText());
           brotE=Double.parseDouble(broteinheiten.getText());
           kohy=Double.parseDouble(kohlenhydrate.getText());
           eiw=Double.parseDouble(eiweiss.getText());
           chol=Double.parseDouble(cholesterin.getText());
           fet=Double.parseDouble(fett.getText());
           unFett=Double.parseDouble(ungesFett.getText());
           
           natr=Double.parseDouble(natrium.getText());
           kali=Double.parseDouble(kalium.getText());
           magn=Double.parseDouble(magnesium.getText());
           calc=Double.parseDouble(calcium.getText());
           phosp=Double.parseDouble(phosphor.getText());
           eise=Double.parseDouble(eisen.getText());
           zi=Double.parseDouble(zink.getText());
           
           vitA=Double.parseDouble(vitaminA.getText());
           vitB1=Double.parseDouble(vitaminB1.getText());
           vitB2=Double.parseDouble(vitaminB2.getText());
           vitB6=Double.parseDouble(vitaminB6.getText());
           vitC=Double.parseDouble(vitaminC.getText());
           vitE=Double.parseDouble(vitaminE.getText());
           fols=Double.parseDouble(folsaeure.getText());
           carot=Double.parseDouble(carotin.getText());
       }
       catch(Exception e){
           JOptionPane.showMessageDialog(this, "Falsche Eingabe!", "Error", JOptionPane.ERROR_MESSAGE);
           return;
       }
       

       /**
        * Nahrungsmittel erstellen
        */
       Nahrungsmittel nN= new Nahrungsmittel(name.getText(), kcal, kohy, brotE, eiw, chol, fet, unFett, 
                            natr, kali, magn, calc, phosp, eise, zi,
                            vitA, vitB1, vitB2, vitB6, vitC, vitE, fols, carot);
       
       if(MainPackage.Options.DEBUG){
            System.out.println("Neu: "+neu);
       }
       if(!neu){ // altes Nahrungsmittel wird bearbeitet und an alter Stelle gespeichert
           nahrung.setNahrungsmittelbyIndex(nN,id);
           
       }
       else{    //neues Nahrungsmittel wird hinzugefügt
           nahrung.addNahrungsmittel(nN);
           
       }
       
       
       nahrung.export();
       setVisible(false);
    }//GEN-LAST:event_SaveButtonActionPerformed

    private void AbbrechenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AbbrechenButtonActionPerformed
        setVisible(false);
    }//GEN-LAST:event_AbbrechenButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AbbrechenButton;
    private javax.swing.JButton SaveButton;
    private javax.swing.JTextField broteinheiten;
    private javax.swing.JTextField calcium;
    private javax.swing.JTextField carotin;
    private javax.swing.JTextField cholesterin;
    private javax.swing.JTextField eisen;
    private javax.swing.JTextField eiweiss;
    private javax.swing.JTextField fett;
    private javax.swing.JTextField folsaeure;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField kalium;
    private javax.swing.JTextField kiloCal;
    private javax.swing.JTextField kohlenhydrate;
    private javax.swing.JTextField magnesium;
    private javax.swing.JTextField name;
    private javax.swing.JTextField natrium;
    private javax.swing.JTextField phosphor;
    private javax.swing.JTextField ungesFett;
    private javax.swing.JTextField vitaminA;
    private javax.swing.JTextField vitaminB1;
    private javax.swing.JTextField vitaminB2;
    private javax.swing.JTextField vitaminB6;
    private javax.swing.JTextField vitaminC;
    private javax.swing.JTextField vitaminE;
    private javax.swing.JTextField zink;
    // End of variables declaration//GEN-END:variables


}
